layui.config({
    base: basePath,
    version: skyeyeVersion
}).extend({
    window: 'js/winui.window'
}).define(['window', 'jquery', 'winui'], function (exports) {
    winui.renderColor();
    layui.use(['form'], function (form) {
        var $ = layui.$;
        var tenantId = GetUrlParam("tenantId") || '';

        // Initialize sex enum
        skyeyeClassEnumUtil.showEnumDataListByClassName("sexEnum", 'radio', "userSex", '', form);

        form.on('submit(formSetAdmin)', function (data) {
            if (winui.verifyForm(data.elem)) {
                var params = {
                    userName: $('#userName').val(),
                    phone: $('#phone').val(),
                    userSex: $('#userSex input:radio:checked').val(),
                    tenantId: tenantId,
                    userIdCard: $('#userIdCard').val(),
                    password: $('#password').val()
                };
                AjaxPostUtil.request({
                    url: reqBasePath + 'addTenantAdminUser',
                    params: params,
                    type: 'json',
                    method: 'POST',
                    callback: function (json) {
                        winui.window.msg('设置管理员成功', { icon: 1, time: 2000 });
                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }, 1000);
                    }
                });
            }
            return false;
        });

        matchingLanguage();
        form.render();
    });
});
